package br.ufla.pgcc.oomeasures.plugin.chart;

import java.awt.Font;
import java.util.List;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;

import br.ufla.pgcc.oomeasures.ItemMeasured;


	public class PieChart {


		/**
		 * Cria um grafico de pizza com os itens medidos
		 *
		 */
		public JFreeChart createPieChart(ItemMeasured itemsMeasured) {

			
			double pieRatio = 0.0;
			
			DefaultPieDataset PieChartDataset = new DefaultPieDataset();
			String projectName = "";
			
			if (itemsMeasured != null) {
				List<ItemMeasured> items = itemsMeasured.getChildren();
				projectName = itemsMeasured.getName();
				
				for (ItemMeasured item : items) {
					pieRatio += item.getValue();
				}

				for (ItemMeasured item : items) {
					PieChartDataset.setValue(item.getName(), item.getValue() / pieRatio);
				}
				
			}
				
				JFreeChart pieChart = ChartFactory.createPieChart("Measures of the project " + projectName,
						PieChartDataset,
						false,
						true,
						false);
			
				pieChart.getTitle().setFont(new Font("MS Sans Serif", Font.BOLD, 14));
				
       
			
			return pieChart;
			
		}
	
}
